package com.jeegit.ecms.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.jeegit.common.core.domain.Ztree;
import com.jeegit.common.utils.DateUtils;
import com.jeegit.common.utils.IdUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeegit.ecms.mapper.CmsCollectionCategoryMapper;
import com.jeegit.ecms.domain.CmsCollectionCategory;
import com.jeegit.ecms.service.ICmsCollectionCategoryService;
import com.jeegit.ecms.utils.ECMSUtils;
import com.jeegit.common.core.text.Convert;

/**
 * 栏目分类Service业务层处理
 * 
 * @author jeegit
 * @date 2022-06-27
 */
@Service
public class CmsCollectionCategoryServiceImpl implements ICmsCollectionCategoryService 
{
    @Autowired
    private CmsCollectionCategoryMapper cmsCollectionCategoryMapper;

    /**
     * 查询栏目分类
     * 
     * @param id 栏目分类主键
     * @return 栏目分类
     */
    @Override
    public CmsCollectionCategory selectCmsCollectionCategoryById(Long id)
    {
        return cmsCollectionCategoryMapper.selectCmsCollectionCategoryById(id);
    }

    /**
     * 查询栏目分类列表
     * 
     * @param cmsCollectionCategory 栏目分类
     * @return 栏目分类
     */
    @Override
    public List<CmsCollectionCategory> selectCmsCollectionCategoryList(CmsCollectionCategory cmsCollectionCategory)
    {
        return cmsCollectionCategoryMapper.selectCmsCollectionCategoryList(cmsCollectionCategory);
    }

    /**
     * 新增栏目分类
     * 
     * @param cmsCollectionCategory 栏目分类
     * @return 结果
     */
    @Override
    public int insertCmsCollectionCategory(CmsCollectionCategory cmsCollectionCategory)
    {
    	cmsCollectionCategory.setId(IdUtils.getInstance(3l).nextId());
    	cmsCollectionCategory.preInsert(cmsCollectionCategory);
    	return cmsCollectionCategoryMapper.insertCmsCollectionCategory(cmsCollectionCategory);
    }

    /**
     * 修改栏目分类
     * 
     * @param cmsCollectionCategory 栏目分类
     * @return 结果
     */
    @Override
    public int updateCmsCollectionCategory(CmsCollectionCategory cmsCollectionCategory)
    {
    	cmsCollectionCategory.preUpdate(cmsCollectionCategory);
    	return cmsCollectionCategoryMapper.updateCmsCollectionCategory(cmsCollectionCategory);
    }

    /**
     * 批量删除栏目分类
     * 
     * @param ids 需要删除的栏目分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsCollectionCategoryByIds(String ids)
    {
        return cmsCollectionCategoryMapper.deleteCmsCollectionCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除栏目分类信息
     * 
     * @param id 栏目分类主键
     * @return 结果
     */
    @Override
    public int deleteCmsCollectionCategoryById(Long id)
    {
        return cmsCollectionCategoryMapper.deleteCmsCollectionCategoryById(id);
    }

    /**
     * 查询栏目分类树列表
     * 
     * @return 所有栏目分类信息
     */
    @Override
    public List<Ztree> selectCmsCollectionCategoryTree()
    {
        List<CmsCollectionCategory> cmsCollectionCategoryList = cmsCollectionCategoryMapper.selectCmsCollectionCategoryList(new CmsCollectionCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        ztrees=ECMSUtils.addTreeRoot(ztrees);//追加根目录
        for (CmsCollectionCategory cmsCollectionCategory : cmsCollectionCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(cmsCollectionCategory.getId());
            ztree.setpId(cmsCollectionCategory.getParentId());
            ztree.setName(cmsCollectionCategory.getTitle());
            ztree.setTitle(cmsCollectionCategory.getTitle());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
